home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / class / strassoc.c < prev    next >
C/C++ Source or Header  |  1997-04-16  |  6KB  |  217 lines

  1.  
  2.  
  3. /*  Copyright (c) 1993-1996 Algorithms Corporation  */
  4. /*  All rights reserved.  */
  5.  
  6.  
  7.  
  8.  
  9. /*  This file automatically generated by dpp - do not edit  */
  10.  
  11. #define    DPP_STRATEGY    2
  12. #define    DPP_FASTWIDE    0
  13.  
  14.  
  15.  
  16. #line 15 "strassoc.d"
  17. #include <string.h> 
  18. #include <math.h> 
  19. #include "memalloc.h" 
  20.  
  21. #define    CLASS    StringAssociation_c
  22. #define    ivType    StringAssociation_iv_t
  23.  
  24. #include "generics.h"
  25.  
  26. object    StringAssociation_c;
  27.  
  28.  
  29. #line 30 "strassoc.c"
  30. typedef struct  _StringAssociation_iv_t  {
  31.     char * iKey;
  32.     object iValue;
  33. }    StringAssociation_iv_t;
  34.  
  35.  
  36.  
  37. #line 25 "strassoc.d"
  38. cmeth objrtn StringAssociation_cm_gNewWithStrObj(object self, char *key, object value)
  39.     int len = key ? strlen(key) : 0; 
  40.     object assoc; 
  41.     ivType *iv; 
  42.  
  43.     ChkArgNul(value, 3); 
  44.     assoc = oSuper(StringAssociation_c, gNew, self)(self); 
  45.     iv = ivPtr(assoc); 
  46.     iv->iKey = (char *) MA_malloc(len+1, &iv->iKey); 
  47.     strcpy(iv->iKey, key ? key : ""); 
  48.     iv->iValue = value; 
  49.     return assoc; 
  50.  
  51. imeth objrtn StringAssociation_im_gDeepCopy(object self)
  52. { StringAssociation_iv_t *iv = GetIVs(StringAssociation, self);
  53.     object nobj; 
  54.     ivType *iv2; 
  55.  
  56.     nobj = oSuper(StringAssociation_c, gDeepCopy, self)(self); 
  57.     iv2 = ivPtr(nobj); 
  58.     if (iv->iKey) { 
  59.         iv2->iKey = (char *) MA_malloc(strlen(iv->iKey)+1, &iv2->iKey); 
  60.         strcpy(iv2->iKey, iv->iKey); 
  61.     } 
  62.     if (iv->iValue) 
  63.         iv2->iValue = gDeepCopy(iv->iValue); 
  64.     return nobj; 
  65.  
  66. imeth objrtn StringAssociation_im_gCopy(object self)
  67. { StringAssociation_iv_t *iv = GetIVs(StringAssociation, self);
  68.     object nobj; 
  69.     ivType *iv2; 
  70.  
  71.     nobj = oSuper(StringAssociation_c, gCopy, self)(self); 
  72.     iv2 = ivPtr(nobj); 
  73.     if (iv->iKey) { 
  74.         iv2->iKey = (char *) MA_malloc(strlen(iv->iKey)+1, &iv2->iKey); 
  75.         strcpy(iv2->iKey, iv->iKey); 
  76.     } 
  77.     iv2->iValue = iv->iValue; 
  78.     return nobj; 
  79.  
  80. imeth objrtn StringAssociation_im_gValue(object self)
  81. { StringAssociation_iv_t *iv = GetIVs(StringAssociation, self);
  82.     return iv->iValue; 
  83.  
  84. imeth objrtn StringAssociation_im_gChangeValue(object self, object value)
  85. { StringAssociation_iv_t *iv = GetIVs(StringAssociation, self);
  86.     object ret; 
  87.     ChkArgNul(value, 2); 
  88.     ret = iv->iValue; 
  89.     iv->iValue = value; 
  90.     return ret; 
  91.  
  92. imeth char * StringAssociation_im_gStringKey(object self)
  93. { StringAssociation_iv_t *iv = GetIVs(StringAssociation, self);
  94.     return iv->iKey; 
  95.  
  96. imeth objrtn StringAssociation_im_gChangeStringKey(object self, char *key)
  97. { StringAssociation_iv_t *iv = GetIVs(StringAssociation, self);
  98.     int len = key ? strlen(key) : 0; 
  99.  
  100.     if (iv->iKey) { 
  101.         if (len > (int) strlen(iv->iKey)) 
  102.             iv->iKey = (char *) MA_realloc(iv->iKey, len+1); 
  103.     } else 
  104.         iv->iKey = (char *) MA_malloc(len+1, &iv->iKey); 
  105.     strcpy(iv->iKey, key ? key : ""); 
  106.     return self; 
  107.  
  108. imeth objrtn StringAssociation_im_gDispose(object self)
  109. { StringAssociation_iv_t *iv = GetIVs(StringAssociation, self);
  110.     if (iv->iKey) 
  111.         MA_free(iv->iKey); 
  112.     return oSuper(StringAssociation_c, gDispose, self)(self); 
  113.  
  114. imeth objrtn StringAssociation_im_gDeepDispose(object self)
  115. { StringAssociation_iv_t *iv = GetIVs(StringAssociation, self);
  116.     if (iv->iKey) 
  117.         MA_free(iv->iKey); 
  118.     if (iv->iValue) 
  119.         gDeepDispose(iv->iValue); 
  120.     return oSuper(StringAssociation_c, gDeepDispose, self)(self); 
  121.  
  122. imeth objrtn StringAssociation_im_gStringRepValue(object self)
  123. { StringAssociation_iv_t *iv = GetIVs(StringAssociation, self);
  124.     object s, t; 
  125.  
  126.     t = iv->iValue ? gStringRepValue(iv->iValue) : (object) NULL; 
  127.     s = vSprintf(String, "( \"%s\", ", iv->iKey ? iv->iKey : "(null)"); 
  128.     vBuild(s, NULL, t ? (char *) t : "(null)", " )", NULL); 
  129.     if (t) 
  130.         gDispose(t); 
  131.     return s; 
  132.  
  133. imeth int StringAssociation_im_gHash(object self)
  134. { StringAssociation_iv_t *iv = GetIVs(StringAssociation, self);
  135.     register char c = 'a'; 
  136.     char *s = iv->iKey; 
  137.     double t; 
  138.     register unsigned short k=0; 
  139.  
  140.     if (s) 
  141.         while (*s) 
  142.         k += *s++ ^ c++; 
  143.     t = .6125423371 * k; 
  144.     t = t < 0.0 ? -t : t; 
  145.     return (int) (BIG_INT * (t - floor(t))); 
  146.  
  147. imeth int StringAssociation_im_gCompare(object self, object arg)
  148. { StringAssociation_iv_t *iv = GetIVs(StringAssociation, self);
  149.     ChkArg(arg, 2); 
  150.     return strcmp(iv->iKey?iv->iKey:"", gStringKey(arg)); 
  151.  
  152.  
  153. #line 167 "strassoc.c"
  154.  
  155. objrtn    StringAssociation_initialize(void)
  156. {
  157.     static  CRITICALSECTION  cs;
  158.     static  int volatile once = 0;
  159.  
  160.     ENTERCRITICALSECTION(_CI_CS_);
  161.     if (!once) {
  162.         INITIALIZECRITICALSECTION(cs);
  163.         once = 1;
  164.     }
  165.     LEAVECRITICALSECTION(_CI_CS_);
  166.  
  167.     ENTERCRITICALSECTION(cs);
  168.  
  169.     if (StringAssociation_c) {
  170.         LEAVECRITICALSECTION(cs);
  171.         return StringAssociation_c;
  172.     }
  173.     INHIBIT_THREADER;
  174.     Association_initialize();
  175.     if (StringAssociation_c)  {
  176.         ENABLE_THREADER;
  177.         LEAVECRITICALSECTION(cs);
  178.         return StringAssociation_c;
  179.     }
  180.     StringAssociation_c = gNewClass(Class, "StringAssociation", sizeof(StringAssociation_iv_t), 0, Association, END);
  181.     cMethodFor(StringAssociation, gNewWithStrObj, StringAssociation_cm_gNewWithStrObj);
  182.     iMethodFor(StringAssociation, gCompare, StringAssociation_im_gCompare);
  183.     iMethodFor(StringAssociation, gStringKey, StringAssociation_im_gStringKey);
  184.     iMethodFor(StringAssociation, gDispose, StringAssociation_im_gDispose);
  185.     iMethodFor(StringAssociation, gChangeStringKey, StringAssociation_im_gChangeStringKey);
  186.     iMethodFor(StringAssociation, gValue, StringAssociation_im_gValue);
  187.     iMethodFor(StringAssociation, gGCDispose, StringAssociation_im_gDispose);
  188.     iMethodFor(StringAssociation, gStringRepValue, StringAssociation_im_gStringRepValue);
  189.     iMethodFor(StringAssociation, gHash, StringAssociation_im_gHash);
  190.     iMethodFor(StringAssociation, gChangeValue, StringAssociation_im_gChangeValue);
  191.     iMethodFor(StringAssociation, gCopy, StringAssociation_im_gCopy);
  192.     iMethodFor(StringAssociation, gDeepDispose, StringAssociation_im_gDeepDispose);
  193.     iMethodFor(StringAssociation, gDeepCopy, StringAssociation_im_gDeepCopy);
  194.  
  195.     ENABLE_THREADER;
  196.  
  197.     LEAVECRITICALSECTION(cs);
  198.  
  199.     return StringAssociation_c;
  200. }
  201.  
  202.  
  203.  
  204.